package cn.edu.zut.service.impl;


import cn.edu.zut.dao.IBookLendInfoDao;
import cn.edu.zut.domin.BookLendInfo;
import cn.edu.zut.service.IBookLendInfoService;
import cn.edu.zut.service.IBookService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

//关于还书的函数，服务层的实体类。
// 需要将具体方法在接口实现
@Service//服务层注解
@Transactional
public class BookLendInfoServiceImpl implements IBookLendInfoService {
    @Autowired
    private IBookLendInfoDao iBookLendInfoDao;
    @Autowired
    IBookService iBookService;
    //定义了两个接口实体来调用方法

    public BookLendInfoServiceImpl() {
        super();
    }
    //
    @Override
    public void saveBookLendInfo(BookLendInfo bookLendInfo) {
        iBookLendInfoDao.insertBookLendInfo(bookLendInfo);
    }
    //保存的方法
    @Override
    public void deleteBookLendInfo(String bookId, String readerId) {
        iBookLendInfoDao.delectBookLendInfo(bookId, readerId);
    }
    //删除的方法
    @Override
    public void updateBookLendInfo(BookLendInfo bookLendInfo) {

        iBookLendInfoDao.setNewInfo(bookLendInfo);
    }

//更新

    @Override
    public List<BookLendInfo> findBookLendInfoByBook(int page, int size, String bookId) {
        PageHelper.startPage(page,size);
        return iBookLendInfoDao.getBookLendInfoByBookId(bookId);

    }

    @Override
    public List<BookLendInfo> findAllBookLendInfo(int page, int size) {
        PageHelper.startPage(page,size);
        return iBookLendInfoDao.findAll();
    }
//查找方法
    @Override
    public List<BookLendInfo> findBookLendInfoByReader(int page, int size, String readerId) {
        PageHelper.startPage(page,size);
        return iBookLendInfoDao.getBookLendInfoByReaderId(readerId);
    }
    //通过读者查询信息，并返回查询数值
    @Override
    public List<BookLendInfo> getBookLendInfoByBookIdAndReaderId(int page, int size, String bookId, String readerId) {
        PageHelper.startPage(page,size);
        System.out.println(bookId+readerId);
        return iBookLendInfoDao.getBookLendInfoByBookIdAndReaderId(bookId,readerId);
    }
    //通过书籍号和读者id查询并得到信息，返回给iBokLenfInfoDao
}
